package com.hemaapp.yjnh.activity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.hemaapp.yjnh.BaseFragmentActivity;
import com.hemaapp.yjnh.R;
import com.hemaapp.yjnh.adapter.TabViewPagerAdapter;
import com.hemaapp.yjnh.fragment.OrderListFragment;

/**买家端普通商品订单列表
 * @author GuiyouZhang
 * 创建时间：2015年7月31日
 * 最后修改时间：2016年8月18日
 */
public class OrderListActivity extends BaseFragmentActivity {

	@Bind(R.id.title_left_btn)
	ImageButton titleLeftBtn;
	@Bind(R.id.title_right_btn)
	Button titleRightBtn;
	@Bind(R.id.title_text)
	TextView titleText;
	@Bind(R.id.layout_tab)
	TabLayout layoutTab;
	@Bind(R.id.viewpager)
	ViewPager viewpager;

	private OrderListFragment allFragment = new OrderListFragment();
	private OrderListFragment unPayFragment = new OrderListFragment();
	private OrderListFragment unDeliveryFragment = new OrderListFragment();
	private OrderListFragment unReceiveFragment = new OrderListFragment();
	private OrderListFragment unCommentFragment = new OrderListFragment();
	private TabViewPagerAdapter pagerAdapter;
	private String billtype = "1";//订单类型	1:普通订单；2:定制订单；3:预约订单；4代付订单
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_custom_orders);
		ButterKnife.bind(this);
		super.onCreate(savedInstanceState);
		initDatas();
	}
	
	private void initDatas() {
		List<String> titles = new ArrayList<>();
		titles.add("全部");
		titles.add("待支付");
		titles.add("待发货");
		titles.add("待收货");
		titles.add("待评价");
		allFragment.setBilltype(billtype);
        unPayFragment.setBilltype(billtype);
        unDeliveryFragment.setBilltype(billtype);
        unReceiveFragment.setBilltype(billtype);
        unCommentFragment.setBilltype(billtype);
		allFragment.setKeytype("1");
        unPayFragment.setKeytype("2");
        unDeliveryFragment.setKeytype("3");
        unReceiveFragment.setKeytype("4");
        unCommentFragment.setKeytype("5");
		List<Fragment> fragments = new ArrayList<>();
		fragments.add(allFragment);
		fragments.add(unPayFragment);
		fragments.add(unDeliveryFragment);
		fragments.add(unReceiveFragment);
		fragments.add(unCommentFragment);
		pagerAdapter = new TabViewPagerAdapter(getSupportFragmentManager(), fragments, titles);
		viewpager.setAdapter(pagerAdapter);
		viewpager.setOffscreenPageLimit(5);
		layoutTab.setTabMode(TabLayout.MODE_FIXED);
		layoutTab.setupWithViewPager(viewpager);
		layoutTab.setTabsFromPagerAdapter(pagerAdapter);
	}

	@Override
	protected void callBeforeDataBack(HemaNetTask hemaNetTask) {

	}

	@Override
	protected void callAfterDataBack(HemaNetTask hemaNetTask) {

	}

	@Override
	protected void callBackForServerSuccess(HemaNetTask hemaNetTask, HemaBaseResult hemaBaseResult) {

	}

	@Override
	protected void callBackForServerFailed(HemaNetTask hemaNetTask, HemaBaseResult hemaBaseResult) {

	}

	@Override
	protected void callBackForGetDataFailed(HemaNetTask hemaNetTask, int i) {

	}

	@Override
	protected void findView() {
	}

	@Override
	protected void getExras() {
		billtype = mIntent.getStringExtra("billtype");
	}

	@Override
	protected void setListener() {
        if (billtype.equals("1"))
		    titleText.setText("我的订单");
        else if (billtype.equals("2"))
            titleText.setText("定制订单");
		titleRightBtn.setVisibility(View.GONE);
	}

	@OnClick({R.id.title_left_btn, R.id.title_right_btn})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.title_left_btn:
				finish();
				break;
			case R.id.title_right_btn:
				break;
		}
	}
//
//	/**评价订单中的商品
//	 * @param goods_id
//	 */
//	public void commitGoods(String goods_id) {
//		Intent itCommit = new Intent(mContext, CommentProductionActivity.class);
//		itCommit.putExtra("goods_id", goods_id);
//		startActivityForResult(itCommit, REQUEST_ORDER_COMMIT);
//	}
//
//	/**申请售后
//	 * @param goods 订单中的商品
//	 * @param recvdate 订单的收货时间
//	 */
//	public void applyAfterSale(BillChild goods, String recvdate) {
//		Intent itCommit = new Intent(mContext, ApplyAfterSalesActivity.class);
//		itCommit.putExtra("goods", goods);
//		itCommit.putExtra("type", 1);
//		itCommit.putExtra("recvdate", recvdate);//确认收货时间
//		startActivityForResult(itCommit, REQUEST_ORDER_AFTERSALE);
//	}
}
